package xin.printk.android.module.note;

import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.constraint.ConstraintLayout;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import xin.printk.android.BasicActivity;
import xin.printk.android.R;
import xin.printk.android.data.entity.NoteItem;
import xin.printk.android.utils.LogUtils;
import xin.printk.android.utils.Mock;
import xin.printk.android.view.adapter.ViewPagerAdapter;


public class NoteActivity extends BasicActivity {

    private ViewPager mNotePager;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_note);
        mNotePager = findViewById(R.id.vp_note_items);
        List<View> views = mockView();
        PagerAdapter mPagerAdapter = new ViewPagerAdapter<>(views);
        mNotePager.setAdapter(mPagerAdapter);
        mNotePager.setOffscreenPageLimit(views.size());
        mNotePager.setPageTransformer(true, new ViewPager.PageTransformer() {
            @Override
            public void transformPage(View page, float position) {
                LogUtils.d("[position]:" + position);
                if (position <= 0) {
                    page.setRotation(45 * position);
                }
            }
        });
    }

    private List<View> mockView() {
        List<View> views = new ArrayList<>();
        List<NoteItem> data = Mock.mockNoteItemData(this);
        LayoutInflater inflater = LayoutInflater.from(this);
        for (int i = 0; i < data.size(); i++) {
            View view = inflater.inflate(R.layout.item_note, mNotePager, false);
            ConstraintLayout layout = view.findViewById(R.id.item_layout);
            TextView title = view.findViewById(R.id.tv_note_title);
            TextView description = view.findViewById(R.id.tv_note_description);
            layout.setBackgroundColor(data.get(i).getColor());
            title.setText(data.get(i).getTitle());
            description.setText(data.get(i).getDescription());
            views.add(view);
        }
        return views;
    }

}
